package com.myhome.money.sentinel.dubbo;

import com.alibaba.csp.sentinel.slots.block.SentinelRpcException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Author: 许路路
 * @Date: 2019/8/12
 */
public class DubboConsumerMain {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
        consumerContext.register(DemoConsumerConfig.class);
        consumerContext.refresh();
        DemoConsumerController demo = consumerContext.getBean(DemoConsumerController.class);

        for (int i = 0; i < 15; i++) {
            try {
                String message = demo.test("Rod");
                System.out.println("Success: " + message);
            } catch (SentinelRpcException ex) {
                System.out.println("Blocked");
            } catch (Exception ex) {
                System.out.println("Exception:" + ex.getMessage());
            }
        }
    }
}
